package com.zrrd.learn.lianxi;

/**
 * 青蛙跳井
 *
 * @author wrn
 * @version 1.0
 * @date 2023/4/23 13:19
 */

public class LanXi1 {

    public static int jumoNo(int well, int jump, int down) {

        //容错处理
        if (well < 0) {
            //错误提示
            throw new RuntimeException("参数well不能为负数");
        }
        if (down >= jump) {
            throw new RuntimeException("您给的参数没有意义，青蛙跳的高度不能低于下滑高度");
        }

        int index = 0;
        for (int i = 0; (i = i + jump) <= well; i -= down) {
            index++;
        }
        return index;
    }

    /**
     * 方法 while
     * 代码块里面的变量   形
     *
     * @param well 井深
     * @param jump 跳多高
     * @param down 下滑多少
     * @return index 次数
     */
    public static int jumpNoWithWhile(int well, int jump, int down) {

//        checkArguments(well, jump, down);

        int frogPosition = 0;
        int index = 0;
        //不明确次数使用while
        while ((frogPosition += jump) < well) {
            index++;
            frogPosition -= down;
        }
        return index;
    }


    public static void main(String[] args) {
        System.out.println(jumoNo(70, 3, 1));
        // 1 条件  井 7  3 1
        //定义条件
        int well = 70;
        int jump = 3;
        int down = 1;
        int index = 0;
        //循环
        // 2 循环条件处理
        for (int i = 0; i < well - 1; i += jump) {
            index++;
            if (i > 0 && i < well) {
                i -= down;
            } else {
                i = i;
            }
        }
        System.out.println(index + "次");


        // System.out.println(jumpNo(7, 1, 3));

//        System.out.println(jumpNoWithWhile(7, 3, 1));

//        /******************/
//        a b c (4以内0,不能重复)
//        数据帮助类 Math.random()*5;
//        (int)(Math.random()*5);
        int a = 0, b = 0, c = 0;
        while (a == b || a == c || b == c) {
            a = (int) (Math.random() * 5);
            b = (int) (Math.random() * 5);
            c = (int) (Math.random() * 5);
        }
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);

//是否可以通过取出相应同学姓名

//第一个不重复的4以内的整数
        int index1 =0;
        while(index1 < 3){
            int temp = (int)(Math.random() * 4)+1;

            if(temp != a && temp != b && temp != c){
                index1++;
                if(index1 == 1){
                    a = temp;
                }
                if(index1 == 2){
                    b = temp;
                }
                if(index1 == 3){
                    c = temp;
                }
            }
        }
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);






    }

}


